﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Collections;

namespace Agresso.Interface.Layer.Domain
{
    public class Statement
    {
        public string headfixture_type = string.Empty;
        public string head_fixture_name = string.Empty;
        public string profit_centre = string.Empty;
        public string statement_header = string.Empty;
        public string registered_owner = string.Empty;
        public string vessel_name = string.Empty;
        public int voyage_no =0;
        public string disponent_owner = string.Empty;
        public string created_by = string.Empty;
        public string statement_number = string.Empty;
        public DateTime statement_date = new DateTime(1900,1,1);
        public DateTime statement_due_date = new DateTime(1900, 1, 1);
        public string statement_issued = string.Empty;
        public string statement_currency = string.Empty;
        public decimal remittance_amount = 0;
        public string charge_description= string.Empty;
        public int start_voyage_no = 0;
        public string statement_type= string.Empty;
        public string charge_type = string.Empty;
        public string company = string.Empty;
        public string raised_to_final_by = string.Empty;
        public string voyage_ref = string.Empty;
        public decimal statement_total = 0;
        public decimal charge_amount = 0;
        public decimal charge_address_amount= 0;
        public decimal charge_co_comm_amount = 0;
        public int narrative_line = 0;//--
        public int i_statement_id = 0;
        public string pickup_flag = string.Empty;
        public DateTime pickup_date = new DateTime(1900, 1, 1);
        public DateTime pickup_update_date = new DateTime(1900, 1, 1);
        public DateTime insert_date = new DateTime(1900, 1, 1);
        public string remarks = string.Empty;
        public string batch_id = string.Empty;
        public long charge_id = 0;
        public string fixed_by = "POSTFIX";
        public string vessel_sid = "";

        public IList Items = new ArrayList();
        public Statement Header = null;
        public Statement()
        { }
        public Statement(SqlDataReader rd, bool isfrominterface)
        {
            headfixture_type = rd["headfixture_type"] is DBNull ? headfixture_type : rd["headfixture_type"].ToString();
            head_fixture_name = rd["head_fixture_name"] is DBNull ? head_fixture_name : rd["head_fixture_name"].ToString();
            profit_centre = rd["profit_centre"] is DBNull ? profit_centre : rd["profit_centre"].ToString();
            statement_header = rd["statement_header"] is DBNull ? statement_header : rd["statement_header"].ToString();
            registered_owner = rd["registered_owner"] is DBNull ? registered_owner : rd["registered_owner"].ToString();
            vessel_name = rd["vessel_name"] is DBNull ? vessel_name : rd["vessel_name"].ToString();
            vessel_sid = rd["vessel_code"] is DBNull ? "" : rd["vessel_code"].ToString();
            try
            {
                voyage_no = rd["voyage_no"] is DBNull ? voyage_no : Convert.ToInt16(rd["voyage_no"]);
            }
            catch
            { }
            disponent_owner = rd["disponent_owner"] is DBNull ? disponent_owner : rd["disponent_owner"].ToString();
            created_by = rd["created_by"] is DBNull ? created_by : rd["created_by"].ToString();
            statement_number = rd["statement_number"] is DBNull ? statement_number : rd["statement_number"].ToString();
            statement_date = rd["statement_date"] is DBNull ? statement_date : Convert.ToDateTime(rd["statement_date"]);
            statement_due_date = rd["statement_due_date"] is DBNull ? statement_due_date : Convert.ToDateTime(rd["statement_due_date"]);
            statement_issued = rd["statement_issued"] is DBNull ? statement_issued : rd["statement_issued"].ToString();
            statement_currency = rd["statement_currency"] is DBNull ? statement_currency : rd["statement_currency"].ToString();
            remittance_amount = rd["remittance_amount"] is DBNull ? remittance_amount : Convert.ToDecimal(rd["remittance_amount"]);
            charge_description = rd["charge_description"] is DBNull ? charge_description : rd["charge_description"].ToString();
            start_voyage_no = rd["start_voyage_no"] is DBNull ? start_voyage_no : Convert.ToInt16(rd["start_voyage_no"]);
            statement_type = rd["statement_type"] is DBNull ? statement_type : rd["statement_type"].ToString();
            charge_type = rd["charge_type"] is DBNull ? charge_type : rd["charge_type"].ToString();
            company = rd["company"] is DBNull ? company : rd["company"].ToString();
            raised_to_final_by = rd["raised_to_final_by"] is DBNull ? raised_to_final_by : rd["raised_to_final_by"].ToString();
            voyage_ref = rd["voyage_ref"] is DBNull ? voyage_ref : rd["voyage_ref"].ToString();
            statement_total = rd["statement_total"] is DBNull ? statement_total : Convert.ToDecimal(rd["statement_total"]);
            charge_amount = rd["charge_amount"] is DBNull ? charge_amount : Convert.ToDecimal(rd["charge_amount"]);
            charge_address_amount = rd["charge_address_amount"] is DBNull ? charge_address_amount : Convert.ToDecimal(rd["charge_address_amount"]);
            charge_co_comm_amount = rd["charge_co_comm_amount"] is DBNull ? charge_co_comm_amount : Convert.ToDecimal(rd["charge_co_comm_amount"]);
            narrative_line = rd["narrative_line"] is DBNull ? 0 : Convert.ToInt16(rd["narrative_line"]);
            charge_id = rd["charge_id"] is DBNull ? 0 : Convert.ToInt64(rd["charge_id"]);
            fixed_by = rd["fixed_by"] is DBNull ? "POSTFIX" : rd["fixed_by"].ToString();

            if (isfrominterface)
            {
                pickup_flag = rd["pickup_flag"] is DBNull ? "" : rd["pickup_flag"].ToString();
                pickup_date = rd["pickup_date"] is DBNull ? new DateTime(2000, 1, 1) : Convert.ToDateTime(rd["pickup_date"]);
                pickup_update_date = rd["pickup_update_date"] is DBNull ? new DateTime(2000, 1, 1) : Convert.ToDateTime(rd["pickup_update_date"]);
                insert_date = rd["insert_date"] is DBNull ? new DateTime(2000, 1, 1) : Convert.ToDateTime(rd["insert_date"]);
                i_statement_id = rd["i_statement_id"] is DBNull ? 0 : Convert.ToInt32(rd["i_statement_id"]);
                remarks = rd["remarks"] is DBNull ? remarks : rd["remarks"].ToString();
                batch_id = rd["batch_id"] is DBNull ? batch_id : rd["batch_id"].ToString();
            }
        }
        public Statement(SqlDataReader rd)
        {
            statement_number = rd["statement_number"] is DBNull ? statement_number : rd["statement_number"].ToString();
            statement_date = rd["statement_date"] is DBNull ? statement_date : Convert.ToDateTime(rd["statement_date"]);
            pickup_date = rd["pickup_date"] is DBNull ? new DateTime(2000, 1, 1) : Convert.ToDateTime(rd["pickup_date"]);
            remarks = rd["remarks"] is DBNull ? remarks : rd["remarks"].ToString();
        }
        public static Statement StatementFromFreightHireInvoice(SqlDataReader rd)
        {
            Statement st = new Statement();
            st.statement_number = rd["invoice_number"] is DBNull ? st.statement_number : rd["invoice_number"].ToString();
            st.statement_date = rd["invoice_date"] is DBNull ? st.statement_date : Convert.ToDateTime(rd["invoice_date"]);
            st.pickup_date = rd["pickup_date"] is DBNull ? new DateTime(2000, 1, 1) : Convert.ToDateTime(rd["pickup_date"]);
            st.remarks = rd["remarks"] is DBNull ? st.remarks : rd["remarks"].ToString();
            return st;
        }
    }
}
